package o;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;

public final class bnf {
    private static final Handler ˋ = new Handler(ˎ.getLooper());
    private static final HandlerThread ˎ = new HandlerThread("AsyncHandler");

    static {
        ˎ.start();
    }

    public static void ˋ(Runnable runnable) {
        ˋ.post(runnable);
    }

    private static boolean ʼ(long j) {
        SessionDownloadTask ˊ = bnl.ˏ().ˊ(j);
        if (ˊ == null) {
            return false;
        }
        long j2 = 1;
        for (SplitTask splitTask : ˊ.ᐝˊ()) {
            splitTask.ˏ(ˊ.ʾ());
            long j3 = j2 + 1;
            splitTask.ᐝ(j2);
            j2 = j3;
        }
        bnt.ˋ().ˋ(ˊ);
        return true;
    }

    public static void ॱ(final long j) {
        ˋ(new Runnable() {
            public void run() {
                if (bnf.ʼ(j)) {
                    bnf.ʽ(j);
                }
            }
        });
    }

    public static void ˎ(final long j) {
        ˋ(new Runnable() {
            public void run() {
                bnf.ʼ(j);
            }
        });
    }

    public static void ˊ(final long j) {
        ˋ(new Runnable() {
            public void run() {
                SessionDownloadTask ˊ = bnl.ˏ().ˊ(j);
                if (ˊ != null) {
                    synchronized (ˊ) {
                        if (ˊ.ˈ() != 3) {
                            bnt.ˋ().ˊ(ˊ);
                        }
                    }
                }
            }
        });
    }

    private static void ʽ(long j) {
        Context ॱ = bnl.ˏ().ॱ();
        Intent intent = new Intent("ACTION_ENQUEUE_TASK_SAVE_FINISHED");
        intent.putExtra("sessionId", j);
        intent.setClass(ॱ, bne.class);
        ll.ˏ(ॱ).ˋ(intent);
    }
}
